package com.meilai.project.mapper.finance.supplier;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.meilai.project.dto.finance.supplier.SupplierManageDTO;
import com.meilai.project.entity.finance.supplier.Supplier;
import com.meilai.project.vo.finance.supplier.SupplierVO;
import com.meilai.project.vo.personnel.onTurn.LeaveOfficeApplyVO;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface SupplierManageMapper extends BaseMapper<Supplier> {
    List<SupplierVO> selectPageList(Page<SupplierVO> page, @Param("searchDTO") SupplierManageDTO searchDTO);
    List<SupplierVO> selectPageList(@Param("searchDTO") SupplierManageDTO searchDTO);

    @Select("select a.*,u.`name` as name,c.`job` as job,d.`name` as dep,b.`mobile` as mobile from `leave_office_apply` a left join `roster` b on a.`roster_id`=b.`id` left join `user` u on b.`user_id`= u.`id` left join `user_department_relation` c on u.`id`=c.`user_id` left join `department` d on c.`department_id`=d.`id`" +
            "WHERE c.`main`=1 and a.`id`= #{id}")
    LeaveOfficeApplyVO selectOneById(@Param("id") Long id);

    @Select("select * from `leave_office_apply` where `roster_id`= #{rosterId} and `flow_status` in (3,4)")
    LeaveOfficeApplyVO getBeginOneByRosterId(Long rosterId);

    @Select("select a.*,u.`name` as name,c.`job` as job,d.`name` as dep,b.`mobile` as mobile from `leave_office_apply` a left join `roster` b on a.`roster_id`=b.`id` left join `user` u on b.`user_id`= u.`id` left join `user_department_relation` c on u.`id`=c.`user_id` left join `department` d on c.`department_id`=d.`id`" +
            "WHERE c.`main`=1 and a.`flow_applyer_id`= #{userId}")
    List<LeaveOfficeApplyVO> selectOwnList(Long userId);

    @Select("select u.`name` as name,c.`job` as job,d.`name` as dep,u.`mobile` as mobile,a.`years_end` as contract_end_at from `user` u left join  `roster` a on a.`user_id`=u.`id`  left join `user_department_relation` c on u.`id`=c.`user_id` left join `department` d on c.`department_id`=d.`id` WHERE c.`main`=1 and u.`id`= #{userId}")
    LeaveOfficeApplyVO selectNewAppleyDetail(Long userId);
}
